#include "main.h"
#include "card.h"
#include "player.h"
#include "phases.h"
#include "game.h"

string logFile;
bool debug;

void YuPrint(string message) {
	cout << message << endl;
	
	if(!logFile.empty()) {
		ofstream logOut;
		//open logFile for appending
		logOut.open( logFile.c_str( ), ios :: app );

		if(!logOut.fail())
		{
			time_t timeNow = time(NULL);
			string timeString = asctime(localtime(&timeNow));

			// erase the newline

			timeString.erase(timeString.size( ) - 1);
			logOut << "[" << timeString << "] " << message << endl;
			logOut.close( );
		} else {
			cout << "[MAIN] Error while writing to " + logFile + ": disabling log to file" << endl;
			logFile = string();
		}
	}
}

void DebugPrint(string message) {
	if(debug) {
		cout << message << endl;
	}
}

//
// main
//

int main( int argc, char **argv ) {
	// log file
	logFile = "yuai.log";
	debug = true;
	
	Player *westPlayer = new Player();
	westPlayer->init();
	
	Player *eastPlayer = new Player();
	eastPlayer->init();
	
	Game game;
	game.init(westPlayer, eastPlayer);
	game.runGame();
	
	return 0;
}
